import {fileURLToPath, URL} from "node:url";

import {defineConfig, loadEnv} from "vite";
import vue from "@vitejs/plugin-vue";
import basicSsl from "@vitejs/plugin-basic-ssl";
// https://vitejs.dev/config/
export default defineConfig(({mode}) => {
    console.log(mode)
    return {
        // plugins: [vue(), basicSsl()],
        plugins: [vue()],
        optimizeDeps: {
            include: ["mitt"],
        },
        resolve: {
            alias: {
                "@": fileURLToPath(new URL("./src", import.meta.url)),
            },
        },
        server: {
            port: 5001,
            strictPort: true,
            watch: {
                // 3. tell vite to ignore watching `src-tauri`
                ignored: ["**/src-tauri/**"],
            },
            proxy: {
                "/api/": {
                    // target: "http://api.copy_wechat.test/",
                    target: loadEnv(mode, process.cwd()).VITE_API_URL,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/api\//, "api/v1/"),
                },
            },
        },
        build: {
            chunkSizeWarningLimit: 1600,
            outDir: 'dist',
        },
    };

});


// export default defineConfig({
//     // plugins: [vue(), basicSsl()],
//     plugins: [vue()],
//     optimizeDeps: {
//         include: ["mitt"],
//     },
//     resolve: {
//         alias: {
//             "@": fileURLToPath(new URL("./src", import.meta.url)),
//         },
//     },
//     server: {
//         port: 5173,
//         strictPort: true,
//         watch: {
//             // 3. tell vite to ignore watching `src-tauri`
//             ignored: ["**/src-tauri/**"],
//         },
//         proxy: {
//             "/api/": {
//                 // target: "http://api.copy_wechat.test/",
//                 target: loadEnv(mode, process.cwd()).VITE_API_URL,
//                 changeOrigin: true,
//                 rewrite: (path) => path.replace(/^\/api\//, ""),
//             },
//         },
//     },
//     build: {
//         chunkSizeWarningLimit: 1600,
//         outDir: 'dist',
//     },
// });
